package com.hq.service;

import com.hq.bean.City;
import com.hq.bean.Course;
import com.hq.bean.Student;
import com.hq.bean.User;
import com.hq.dao.StuDAO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StuServiceImpl implements StuService {

    @Resource
    private StuDAO stuDAO;



    @Override
    public List list(Map map) {
        return stuDAO.list(map);
    }

    @Override
    public List<City> cityList(Integer pid) {
        return stuDAO.cityList(pid);
    }

    @Override
    public List<Course> courseList() {
        return stuDAO.courseList();
    }

    @Override
    public int add(Student student, Integer[] cids) {
        // 1：添加主表
        int i=stuDAO.add(student);
        //2 添加中间表
        Map map=new HashMap();
        map.put("sid",student.getSid());
        map.put("cids",cids);
        stuDAO.addMi(map);
        return i;
    }

    @Override
    public int delStu(Integer sid) {
        int i = stuDAO.delStu(sid);
        stuDAO.delMi(sid);
        return i;
    }

    @Override
    public int delsStu(String sids) {
      int i=  stuDAO.delsStu(sids);
        stuDAO.delsMi(sids);
        return i;
    }

    @Override
    public Map getInfoBySid(Integer sid) {
        return stuDAO.getInfoBySid(sid);
    }

    @Override
    public int upd(Student student, Integer[] cids) {
        // 1：修改主表
        int i=stuDAO.updStu(student);
        //2:删除中间表
        stuDAO.delMi(student.getSid());
        //3:添加中间表
        Map map=new HashMap();
        map.put("sid",student.getSid());
        map.put("cids",cids);
        stuDAO.addMi(map);

        return i;
    }

    @Override
    public int saveReg(User user) {
        return stuDAO.saveReg(user);
    }

    @Override
    public User login(User user) {
        return stuDAO.login(user);
    }

    @Override
    public int addLog(Object args) {
        return stuDAO.addLog(args);
    }
}
